package cn.wolfcode.rbac.service.impl;

import cn.wolfcode.rbac.domain.Employee;
import cn.wolfcode.rbac.mapper.DepartmentMapper;
import cn.wolfcode.rbac.service.ILoginService;
import cn.wolfcode.rbac.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2020/7/13 0013.
 */
@Service
public class LoginServiceImpl implements ILoginService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public void login(String username, String password) {
        // 根据账号和密码去数据库中去查询是否有这么一条数据
        Employee e =departmentMapper.selectUserAndPassword(username,password);
        // 如果 e == null 说明之前是没有这么一个用户
        if(e == null){
            throw new RuntimeException("账号或者密码不正确");
        }
        //把查询出来的这个对象放入到session当中
        UserContext.setCurrent(e);
    }
}
